package com.cssw.fyzb.busi.service.acct;

import com.cssw.fyzb.busi.config.TpsClient;
import com.cssw.fyzb.busi.model.tps.CreateAdapayDrawcashVo;
import com.cssw.fyzb.busi.model.tps.CreateAdapayMemberVo;
import com.cssw.fyzb.busi.model.tps.CreateAdapaySettleAcctVo;
import com.cssw.fyzb.busi.model.tps.DeleteAdapayMemberVo;
import com.cssw.fyzb.busi.util.*;
import com.cssw.fyzb.core.dao.acct.*;
import com.cssw.fyzb.core.dao.system.SysParamDao;
import com.cssw.fyzb.core.dao.team.UserTreeDao;
import com.cssw.fyzb.core.dao.user.UserDao;
import com.cssw.fyzb.core.dao.user.UserExtDao;
import com.cssw.fyzb.core.eao.acct.AcctLogEao;
import com.cssw.fyzb.core.exception.BizException;
import com.cssw.fyzb.core.model.dodb.*;
import com.cssw.fyzb.core.util.StringUtil;
import com.cssw.fyzb.core.util.TimeUtil;
import com.ydn.appserver.Request;
import com.ydn.appserver.Response;
import com.ydn.dbframe.plugin.activerecord.Db;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.concurrent.atomic.AtomicReference;

/**
 * @Author zhouxu
 * @create 2020-12-25 20:07
 */
@Service
public class UserCashOutServiceImpl implements UserCashOutService {

    private static final Logger logger = LoggerFactory.getLogger(UserCashOutServiceImpl.class);

    @Autowired
    private UserCashOutDao cashOutDao;

    @Autowired
    private AcctDao acctDao;

    @Autowired
    private AcctLogEao acctLogEao;

    @Autowired
    private SysParamDao sysParamDao;

    @Autowired
    private AdapayAcctDao adapayAcctDao;

    @Autowired
    private OutAcctDao outAcctDao;

    @Autowired
    private UserDao userDao;

    @Autowired
    private TpsClient tpsClient;

    @Value("${cash.bank.cashType:T1}")
    private String cashType;

    //新老用户注册时间规则
    @Value("${task.limitDate:2021-01-21 00:00:00}")
    private String limitDateStr;

    @Autowired
    private UserTreeDao userTreeDao;

    @Autowired
    private TeamGzPriceDao teamGzPriceDao;

    @Autowired
    private UserExtDao userExtDao;

    @Override
    public void cashOutYCoin(Long userId, BigDecimal cashOutFee, String cashAcctType, Long bankId) {
        if (!NumberUtil.isWholeNumber(cashOutFee)) {
            BizUtil.exception("提现必须是整数");
        }
        int cashOutRatio = 0;
        BigDecimal handlingFee = BigDecimal.ZERO;
        SysParam sysParam = sysParamDao.findByCode(SysParam.Y_EXCHANGE_R_RATIO);
        BigDecimal cashAmount = cashOutFee.multiply(new BigDecimal(sysParam.getParamValue()));
        UserBank userBank = null;
        User user = userDao.getById(userId);
        if (!User.FACE_AUTH_YES.equals(user.getFaceAuth())) {
            BizUtil.exception("您还未实名");
        }
        if (user.isFrozen()) {
            BizUtil.exception("您的账号异常");
        }
        Acct acct = acctDao.queryYAcct(userId);
        if (acct.getBalanceFee().compareTo(cashOutFee) < 0) {
            BizUtil.exception(Bizs.ERROR_BALANCE_LESS);
        }

        //银行卡提现需要记录日志
        if ("3".equals(cashAcctType)) {
            userBank = outAcctDao.getBankById(bankId);
            if (null == userBank) {
                BizUtil.exception("银行卡信息异常");
            }
        }

        UserBank finalUserBank = userBank;
        AtomicReference<Long> cashId = new AtomicReference<>();
        Db.tx(() -> {

            //提现方式（1微信 2支付宝 3银行卡）
            if ("1".equals(cashAcctType)) {
                UserWechat userWechat = outAcctDao.getWechatById(userId);
                if (null == userWechat) {
                    BizUtil.exception("您未配置微信信息！");
                }
                cashId.set(cashOutDao.addCashOut(userId, cashOutRatio, cashOutFee, handlingFee, cashAmount, cashAcctType, acct.getAcctId(), acct.getAcctType()));

                cashOutDao.addCashOutWechat(cashId.get(), userWechat.getWechatNo(), userWechat.getRealName(), userWechat.getReceQrCode());

                cashOutDao.saveCashOutLog(cashId.get(), UserCashOut.STATUS_INIT, UserCashOut.CASH_STATUS_AUTO_FAIL, "微信提现中");
                cashOutDao.updateCashStatus(cashId.get(), UserCashOut.CASH_STATUS_AUTO_FAIL);

            } else if ("2".equals(cashAcctType)) {
                UserAli userAli = outAcctDao.getAliById(userId);
                if (null == userAli) {
                    BizUtil.exception("您未配置支付宝信息！");
                }
                cashId.set(cashOutDao.addCashOut(userId, cashOutRatio, cashOutFee, handlingFee, cashAmount, cashAcctType, acct.getAcctId(), acct.getAcctType()));

                cashOutDao.addCashOutAli(cashId.get(), userAli.getAliNo(), userAli.getRealName(), userAli.getReceQrCode());

                cashOutDao.saveCashOutLog(cashId.get(), UserCashOut.STATUS_INIT, UserCashOut.CASH_STATUS_AUTO_FAIL, "支付宝提现中");
                cashOutDao.updateCashStatus(cashId.get(), UserCashOut.CASH_STATUS_AUTO_FAIL);
            } else {

                cashId.set(cashOutDao.addCashOut(userId, cashOutRatio, cashOutFee, handlingFee, cashAmount, cashAcctType, acct.getAcctId(),
                        acct.getAcctType()));

                cashOutDao.addCashOutBank(cashId.get(), bankId, finalUserBank.getCardNo(),
                        finalUserBank.getRealName(), finalUserBank.getBankName(), finalUserBank.getOpenBank(),
                        finalUserBank.getBankCode(), finalUserBank.getProvince(), finalUserBank.getCity());

            }

            acctDao.minusYBalance(userId, cashOutFee, cashId.toString(), AcctTradeType.YCOIN_CASH_OUT, BusiType.YCOIN_CASH_OUT);

            //记录es日志
            acctLogEao.save(UuidUtil.get(), acct.getAcctId(), userId, AcctType.ACCT_TYPE_Y, cashOutFee,
                    Acct.FEE_IN_DE_MINUS, cashId.toString(), AcctTradeType.YCOIN_CASH_OUT, AcctTradeType.YCOIN_CASH_OUT_NAME,
                    BusiType.YCOIN_CASH_OUT, new Date());

            return true;
        });


        //先保证事务提交
        if ("3".equals(cashAcctType)) {
            try {
                //提现
                drawCashYsPay(userId, cashId.get(), cashAmount, finalUserBank.getCardNo(),
                        finalUserBank.getRealName(), "personal", finalUserBank.getBankName(), "深圳市");
            } catch (Exception e){
                logger.error("", e);

                cashOutDao.saveCashOutLog(cashId.get(), UserCashOut.STATUS_INIT, UserCashOut.CASH_STATUS_AUTO_FAIL, e.getMessage());
                cashOutDao.updateCashError(cashId.get(), UserCashOut.CASH_STATUS_AUTO_FAIL, "-1", e.getMessage() == null ? "提现异常" : e.getMessage());
            }
        }
    }

    @Override
    public void cashOutGCoin(Long userId, BigDecimal cashOutFee, String cashAcctType, Long bankId) {
        if (!NumberUtil.isWholeNumber(cashOutFee)) {
            BizUtil.exception("提现必须是整数");
        }

        User user = userDao.getById(userId);
        if (!User.FACE_AUTH_YES.equals(user.getFaceAuth())) {
            BizUtil.exception("您还未实名");
        }
        if (user.isFrozen()) {
            BizUtil.exception("您的账号异常");
        }

        if (isNewUser(user)){
            SysParam sysParam = sysParamDao.findByCode(SysParam.NEW_USER_GZ_CASH_SWITCH);
            if (null == sysParam || !"1".equals(sysParam.getParamValue())){
                BizUtil.exception("新会员提现通道未开启");
            }
        } else {
            SysParam sysParam = sysParamDao.findByCode(SysParam.OLD_USER_GZ_CASH_SWITCH);
            if (null == sysParam || !"1".equals(sysParam.getParamValue())){
                BizUtil.exception("老会员提现通道未开启");
            }
        }

        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");

        //获取30天以前：
        Calendar c = Calendar.getInstance();
        c.add(Calendar.DAY_OF_YEAR, -30);
        Date firstDay = c.getTime();

        //获取当前日期
        Calendar ca = Calendar.getInstance();
        Date lastDay = ca.getTime();

        //判断次数
        Integer countNum = cashOutDao.countCurrMonthGzCashNum(userId, firstDay, lastDay, AcctType.ACCT_TYPE_G);
        if (countNum >= 2) {
            BizUtil.exception("您最近一个月内已经提现2次");
        }

        int cashOutRatio = 0;
        BigDecimal handlingFee = BigDecimal.ZERO;
        UserBank userBank = null;

        Acct acct = acctDao.queryGAcct(userId);
        if (acct.getBalanceFee().compareTo(cashOutFee) < 0) {
            BizUtil.exception(Bizs.ERROR_BALANCE_LESS);
        }

        TeamGzPrice teamGzPrice = getTeamGzPrice(user);

        if (null == teamGzPrice
                || teamGzPrice.getPrice() == null
                || teamGzPrice.getPrice().compareTo(BigDecimal.ZERO) < 1){
            BizUtil.exception("您的果子价格为0");
        }

        BigDecimal gzPrice = getGzPrice(teamGzPrice, userId);
        if (gzPrice.compareTo(BigDecimal.ZERO) < 1){
            BizUtil.exception("您的果子价格为0");
        }

        //月限制金额
        BigDecimal monthLimitNum = teamGzPrice.getMonthLimitNum();
        if (null == monthLimitNum){
            monthLimitNum = BigDecimal.ZERO;
        }

        //判断金额
        BigDecimal sumFee = cashOutDao.sumCurrMonthGzCashFee(userId, firstDay, lastDay, AcctType.ACCT_TYPE_G);
        BigDecimal fixSumFee = sumFee.add(cashOutFee);
        if (null != sumFee && fixSumFee.compareTo(monthLimitNum) > 0) {
            BizUtil.exception("最近一个月最多提现"+monthLimitNum.toString()+",您已提现：" + sumFee.setScale(2).toString() + ", 本次提现：" + cashOutFee.setScale(2));
        }

//        if (gzPrice.compareTo(BigDecimal.ZERO) < 1) {
//            BizUtil.exception("您的果子价格为0");
//        }

        BigDecimal cashAmount = cashOutFee.multiply(gzPrice).setScale(2, BigDecimal.ROUND_DOWN);
        //银行卡提现需要记录日志
        if ("3".equals(cashAcctType)) {
            userBank = outAcctDao.getBankById(bankId);
            if (null == userBank) {
                BizUtil.exception("银行卡信息异常");
            }
        }

        UserBank finalUserBank = userBank;
        AtomicReference<Long> cashId = new AtomicReference<>();
        Db.tx(() -> {
            //提现方式（1微信 2支付宝 3银行卡）
            if ("1".equals(cashAcctType)) {
                UserWechat userWechat = outAcctDao.getWechatById(userId);
                if (null == userWechat) {
                    BizUtil.exception("您未配置微信信息！");
                }
                cashId.set(cashOutDao.addCashOut(userId, cashOutRatio, cashOutFee, handlingFee, cashAmount, cashAcctType, acct.getAcctId(), acct.getAcctType()));

                cashOutDao.addCashOutWechat(cashId.get(), userWechat.getWechatNo(), userWechat.getRealName(), userWechat.getReceQrCode());

                cashOutDao.saveCashOutLog(cashId.get(), UserCashOut.STATUS_INIT, UserCashOut.CASH_STATUS_AUTO_FAIL, "微信提现中");
                cashOutDao.updateCashStatus(cashId.get(), UserCashOut.CASH_STATUS_AUTO_FAIL);
            } else if ("2".equals(cashAcctType)) {
                UserAli userAli = outAcctDao.getAliById(userId);
                if (null == userAli) {
                    BizUtil.exception("您未配置支付宝信息！");
                }
                cashId.set(cashOutDao.addCashOut(userId, cashOutRatio, cashOutFee, handlingFee, cashAmount, cashAcctType, acct.getAcctId(), acct.getAcctType()));

                cashOutDao.addCashOutAli(cashId.get(), userAli.getAliNo(), userAli.getRealName(), userAli.getReceQrCode());

                cashOutDao.saveCashOutLog(cashId.get(), UserCashOut.STATUS_INIT, UserCashOut.CASH_STATUS_AUTO_FAIL, "支付宝提现中");
                cashOutDao.updateCashStatus(cashId.get(), UserCashOut.CASH_STATUS_AUTO_FAIL);
            } else {

                cashId.set(cashOutDao.addCashOut(userId, cashOutRatio, cashOutFee, handlingFee, cashAmount, cashAcctType, acct.getAcctId(),
                        acct.getAcctType()));

                cashOutDao.addCashOutBank(cashId.get(), bankId, finalUserBank.getCardNo(),
                        finalUserBank.getRealName(), finalUserBank.getBankName(), finalUserBank.getOpenBank(),
                        finalUserBank.getBankCode(), finalUserBank.getProvince(), finalUserBank.getCity());
            }

            acctDao.minusGBalance(userId, cashOutFee, cashId.toString(), AcctTradeType.GCOIN_CASH_OUT, BusiType.GCOIN_CASH_OUT);

            //记录es日志
            acctLogEao.save(UuidUtil.get(), acct.getAcctId(), userId, AcctType.ACCT_TYPE_G, cashOutFee,
                    Acct.FEE_IN_DE_MINUS, cashId.toString(), AcctTradeType.GCOIN_CASH_OUT, AcctTradeType.GCOIN_CASH_OUT_NAME,
                    BusiType.GCOIN_CASH_OUT, new Date());
            return true;
        });

        //先保证事务提交
        if ("3".equals(cashAcctType)) {
            try {
                //提现
                drawCashYsPay(userId, cashId.get(), cashAmount, finalUserBank.getCardNo(),
                        finalUserBank.getRealName(), "personal", finalUserBank.getBankName(), "深圳市");
            } catch (Exception e) {
                logger.error("", e);
                cashOutDao.saveCashOutLog(cashId.get(), UserCashOut.STATUS_INIT, UserCashOut.CASH_STATUS_AUTO_FAIL, e.getMessage());
                cashOutDao.updateCashError(cashId.get(), UserCashOut.CASH_STATUS_AUTO_FAIL, "-1", e.getMessage() == null ? "提现异常" : e.getMessage());
            }
        }
    }

    private BigDecimal getGzAddPrice(Long userId){
        UserExt userExt = userExtDao.get(userId);
        if (null == userExt) {
            return BigDecimal.ZERO;
        } else {
            if (null == userExt.getGzAddPrice()) {
                return BigDecimal.ZERO;
            } else {
                return userExt.getGzAddPrice();
            }
        }
    }

    private BigDecimal getGzPrice(TeamGzPrice teamGzPrice, Long userId) {
        BigDecimal gzAddPrice = getGzAddPrice(userId);
        if (null == teamGzPrice || null == teamGzPrice.getPrice() || teamGzPrice.getPrice().compareTo(BigDecimal.ZERO) == 0){
            return gzAddPrice;
        }

        return teamGzPrice.getPrice().add(gzAddPrice).setScale(4, BigDecimal.ROUND_DOWN);
    }


    private TeamGzPrice getTeamGzPrice(User user) {
        //新用户逻辑
        Integer teamNum = userTreeDao.getTeamNum(user.getUserId());
        //老用户走团队果子定价
        return teamGzPriceDao.getByNum(teamNum);
    }

    private boolean isNewUser(User user) {
        //判断是否新用户
        Date limitDate = TimeUtil.parse(this.limitDateStr, "yyyy-MM-dd HH:mm:ss");
        if (null != limitDate && null != user.getCreateTime() && user.getCreateTime().before(limitDate)) {
            return false;
        }
        return true;
    }

    @Override
    public void cashOutYConnCallback(String drawcashId, String status) {
        UserCashOut userCashOut = cashOutDao.getByDrawcashId(drawcashId);
        if (null == userCashOut) {
            BizUtil.exception("提现记录不存在");
        }

        if (UserCashOut.STATUS_INIT.equals(userCashOut.getStatus())) {
            BizUtil.exception("提现记录已经被处理");
        }
        cashOutDao.updateStatus(userCashOut.getCashId(), status);

        //如果失败，回退音值
        if (UserCashOut.STATUS_FAIL.equals(status)) {
            acctDao.addYBalance(userCashOut.getUserId(),
                    userCashOut.getCashOutFee(), userCashOut.getCashId().toString(),
                    AcctTradeType.YCOIN_CASH_OUT_REFUND, BusiType.YCOIN_CASH_OUT);
            Acct acct = acctDao.queryYAcct(userCashOut.getUserId());

            //记录es日志
            acctLogEao.save(UuidUtil.get(), acct.getAcctId(), userCashOut.getUserId(), AcctType.ACCT_TYPE_Y, userCashOut.getCashOutFee(),
                    Acct.FEE_IN_DE_ADD, userCashOut.getCashId().toString(), AcctTradeType.YCOIN_CASH_OUT_REFUND, AcctTradeType.YCOIN_CASH_OUT_REFUND_NAME,
                    BusiType.YCOIN_CASH_OUT, new Date());
        }
    }

    private String drawCashYsPay(Long userId, Long cashId, BigDecimal cashAmt,
                                 String bank_account_no, String bank_account_name,
                                 String bank_account_type, String bank_name, String bank_city) {
        SimpleDateFormat ft = new SimpleDateFormat("yyyyMMdd");
        String shopdate = ft.format(new Date());
        String out_trade_no = shopdate + cashId.toString();

        //记录提现单号
        cashOutDao.updateDrawcashId(cashId, out_trade_no);

        Request request = new Request("YsPay");
        request.setParameter("out_trade_no", out_trade_no);
        request.setParameter("shopdate", shopdate);
        request.setParameter("total_amount", cashAmt.toString());
        request.setParameter("bank_account_no", bank_account_no);
        request.setParameter("bank_account_name", bank_account_name);
        //取现类型：personal
        request.setParameter("bank_account_type", bank_account_type);
        request.setParameter("bank_name", bank_name);
        request.setParameter("bank_city", bank_city);

        Response response = tpsClient.send(request);

        if (!response.isSuccess()) {
            cashOutDao.saveCashOutLog(cashId, UserCashOut.STATUS_INIT,  UserCashOut.CASH_STATUS_AUTO_FAIL, response.getString("errorMsg"));
            String errorCode = response.getString("errorCode");
            if (StringUtil.isEmpty(errorCode)){
                errorCode = String.valueOf(response.getCode());
            }
            String errorMsg = response.getString("errorMsg");
            if (StringUtil.isEmpty(errorMsg)){
                errorMsg = String.valueOf(response.getMessage());
            }
            cashOutDao.updateCashError(cashId, UserCashOut.CASH_STATUS_AUTO_FAIL, errorCode, errorMsg);
        } else {
            cashOutDao.saveCashOutLog(cashId, UserCashOut.STATUS_INIT, UserCashOut.CASH_STATUS_AUTO_INIT, "提交银盛提现中");
            cashOutDao.updateCashStatus(cashId, UserCashOut.CASH_STATUS_AUTO_INIT);
        }
        return out_trade_no;
    }

    private String drawcashAdapay(Long userId, Long cashId, BigDecimal cashAmt) {
        Request request = new Request("CreateDrawcashAdapay");
        request.setParameter("userId", userId);
        request.setParameter("orderNo", cashId);
        //取现类型：T1-T+1取现；D1-D+1取现；D0-即时取现。
        request.setParameter("cashType", cashType);
        request.setParameter("cashAmt", cashAmt.setScale(2));
        request.setParameter("remark", "音值提现");

        Response response = tpsClient.send(request);
        if (!response.isSuccess()) {
            throw new BizException(response.getCode(), response.getMessage());
        }

        CreateAdapayDrawcashVo vo = response.getObject("data", CreateAdapayDrawcashVo.class);
        if (null == vo) {
            BizUtil.exception("提现失败.");
        }

        //不能判断状态，返回的是pending
//        String status = vo.getStatus();
//        if (StringUtil.isEmpty(status) || !"succeeded".equals(status)){
//            BizUtil.exception("提现失败");
//        }

        String drawcashId = vo.getId();
        if (StringUtil.isEmpty(drawcashId)) {
            BizUtil.exception("提现失败");
        }

        return drawcashId;
    }

    private boolean isChangeCard(UserBank userBank, AdapayAcct adapayAcct) {
        if (StringUtil.isEmpty(userBank.getBankCode())) {
            BizUtil.exception("银行编码为空！");
        }
        if (StringUtil.isEmpty(userBank.getProvince())
                || StringUtil.isEmpty(userBank.getCity())) {
            BizUtil.exception("银行卡所在省市为空！");
        }

        if (!userBank.getCardNo().equals(adapayAcct.getCardId())) {
            return true;
        }
        if (!userBank.getBankCode().equals(adapayAcct.getBankCode())) {
            return true;
        }
        if (!userBank.getBankName().equals(adapayAcct.getBankName())) {
            return true;
        }
        if (!userBank.getProvince().equals(adapayAcct.getProvCode())) {
            return true;
        }
        if (!userBank.getCity().equals(adapayAcct.getAreaCode())) {
            return true;
        }

        return false;
    }

    private void deleteAdapaySettleAcct(Long userId, String settleAcctId) {
        Request request = new Request("DeleteSettleAcctAdapay");
        request.setParameter("userId", userId);
        request.setParameter("settleAcctId", settleAcctId);

        Response response = tpsClient.send(request);
        if (!response.isSuccess()) {
            throw new BizException(response.getCode(), response.getMessage());
        }
        DeleteAdapayMemberVo vo = response.getObject("data", DeleteAdapayMemberVo.class);
        if (null == vo) {
            BizUtil.exception("操作失败，请检查银行卡信息是否正确");
        }
        String status = vo.getStatus();
        if (StringUtil.isEmpty(status) || !"succeeded".equals(status)) {
            BizUtil.exception("操作失败，请检查银行卡信息是否正确！.");
        }
    }

    private String createAdapaySettleAcct(User user, UserBank userBank) {
        Request request = new Request("CreateSettleAcctAdapay");
        request.setParameter("userId", user.getUserId());
        request.setParameter("userName", user.getUserName());
        request.setParameter("idCard", user.getIdCard());
        request.setParameter("mobile", user.getMobile());

        request.setParameter("bankNo", userBank.getCardNo());
        request.setParameter("bankCode", userBank.getBankCode());
        request.setParameter("bankName", userBank.getBankName());
        request.setParameter("province", userBank.getProvince());
        request.setParameter("area", userBank.getCity());

        Response response = tpsClient.send(request);
        if (!response.isSuccess()) {
            throw new BizException(response.getCode(), response.getMessage());
        }

        CreateAdapaySettleAcctVo vo = response.getObject("data", CreateAdapaySettleAcctVo.class);
        if (null == vo) {
            BizUtil.exception("操作失败，请检查银行卡信息是否正确");
        }
        String status = vo.getStatus();
        if (StringUtil.isEmpty(status) || !"succeeded".equals(status)) {
            BizUtil.exception("操作失败，请检查银行卡信息是否正确.");
        }

        String settleAcctId = vo.getId();
        if (StringUtil.isEmpty(settleAcctId)) {
            BizUtil.exception("操作失败，请检查银行卡信息是否正确");
        }

        return settleAcctId;
    }

    private void createAdapayUser(User user) {
        Request request = new Request("CreateMemberAdapay");
        request.setParameter("userId", user.getUserId());
        request.setParameter("nickName", user.getNickName());
        request.setParameter("sex", user.getSex());
        request.setParameter("mobile", user.getMobile());
        //非常重要--------需要调取结算，不能传入姓名和身份证
        //request.setParameter("userName", user.getUserName());
        //request.setParameter("idCard", user.getIdCard());
        Response response = tpsClient.send(request);
        if (!response.isSuccess()) {
            throw new BizException(response.getCode(), response.getMessage());
        }
        CreateAdapayMemberVo vo = response.getObject("data", CreateAdapayMemberVo.class);
        if (null == vo) {
            BizUtil.exception("同步支付用户出现错误");
        }
        String status = vo.getStatus();
        if (StringUtil.isEmpty(status) || !"succeeded".equals(status)) {
            BizUtil.exception("同步支付用户出现错误.");
        }
    }


    private String getGender(String sex) {
        if (StringUtil.isEmpty(sex)) {
            return "";
        }

        return AdapayAcct.GENDER_MALE.equals(sex) ? "MALE" : "FEMALE";
    }
}
